/*!
 Temelia - Interval tree samples.

 Copyright (C) 2008 Ceata (http://ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "include/samples.h"
#include <temelia/interval_tree.h>

static void sample1()
{
	interval_tree_node_t node;

	PRINT("\n\n Sample 1 started \n\n");

	node = interval_tree_node_new(0, 10, (void *) 0x123);

	PRINT("%d %d %p\n", interval_tree_node_get_inf(node),
			interval_tree_node_get_sup(node), interval_tree_node_get_key(node));
	interval_tree_node_delete(node);

	PRINT("\n\n Sample 1 ended \n\n");
}

static void sample2()
{
	int **x, i, N = 10;
	interval_tree_t tree;

	PRINT("\n\n Sample 2 started \n\n");

	tree = interval_tree_new(0, N);
	PRINT("Data %p, Empty %d, Size %d, Root %p\n",
			interval_tree_get_data(tree), interval_tree_is_empty(tree),
			interval_tree_get_size(tree), interval_tree_get_node(tree, 0));

	x = int_array_new(N, N * N * N);

	for (i = 0; i < N - 1; i++)
		interval_tree_insert(tree, i, i + 1, x[i]);

	PRINT("\nPreorder :\n");
	interval_tree_preorder(tree, int_handler, NULL);

	PRINT("\nInorder :\n");
	interval_tree_inorder(tree, int_handler, NULL);

	PRINT("\nReverse inorder :\n");
	interval_tree_reverse_inorder(tree, int_handler, NULL);

	PRINT("\nPostorder :\n");
	interval_tree_postorder(tree, int_handler, NULL);

	PRINT("\nLevel order :\n");
	interval_tree_level_order(tree, int_handler, NULL);

	PRINT("\nShow indented :\n");
	interval_tree_show_indented(tree, int_level_handler, NULL);

	interval_tree_search(tree, 0, 1, int_handler, NULL);

	interval_tree_remove(tree, 0, N);

	interval_tree_delete(tree);

	int_array_delete(x, N);

	PRINT("\n\n Sample 1 ended \n\n");
}

void run_interval_tree_samples()
{
	sample1();
	sample2();
}
